<%@ Language=VBScript %>
<%Option Explicit%>

<!--#include file="../cons.asp"-->
<!--#include file="../../Common/Database.asp"-->

<%
	response.CacheControl = "no-cache"
	
	Dim oRSAlumnos
	Dim IdMateria, DicMar, CursoDescrip
	
	IdMateria = request("IdMateria")
	DicMar = request("DicMar")
	
	Set oRSAlumnos = GetAlumnosDicMarxMat()
	
	response.Write "<table style=""font-family: Verdana; font-size: 12px;"">"
	
	if not oRSAlumnos.EOF then
		CursoDescrip = oRSAlumnos("CursoDescrip")
	end if
	while not oRSAlumnos.EOF
		response.Write "<tr>"
		if oRSAlumnos("CursoDescrip") <> CursoDescrip then
			
			response.Write "<td colspan=3>&nbsp;</td></tr><tr>"
			CursoDescrip = oRSAlumnos("CursoDescrip")
		end if
		response.Write "<td width=""103px"">" & oRSAlumnos("CursoDescrip") & "</td>"
		response.Write "<td width=""400px"">" & oRSAlumnos("Apellido") & ", " & oRSAlumnos("Nombre") & "</td>"
		
		'if not oRSNotasCuat.EOF then
		'	if oRSAlumnos("IdAlumno") = oRSNotasCuat("IdAlumno") then
		'		response.Write "<td><input size=3 "
		'		if oRSNotasCuat("nota") < 4 then
		'			Response.Write "style=""color: red;"""
		'		end if
		'		if oRSNotasCuat("nota") >= 4 and oRSNotasCuat("nota") <6 then
		'			Response.Write "style=""color: green;"""
		'		end if
		'		if oRSNotasCuat("nota") >=6 then
		'			Response.Write "style=""color: blue;"""
		'		end if
		'		Response.Write " onblur=""this.parentElement.parentElement.cells[0].style.backgroundColor='white';"" onfocus=""this.parentElement.parentElement.cells[0].style.backgroundColor='yellow';"" id=""nota"" name=""nota"" style=""font-family: Verdana; font-weight: bold; font-size:12px;"" onkeyup=""if (this.value >=6) this.style.color='blue'; if (this.value >= 4 && this.value <6) this.style.color='green'; if (this.value < 4) this.style.color='red';"" onkeypress=""if ((event.keyCode <48 || event.keyCode >=58) && (event.keyCode != 46)) return false;"" maxlength=4 type=""text"" value=""" & oRSNotasCuat("nota") & """></td>"
		'		response.Write "<td><input type=""hidden"" id=""alumno"" name=""alumno"" value=""" & oRSNotasCuat("IdNota") & """></td>"
		'		response.Write "<td><input type=""hidden"" id=""operacion"" name=""operacion"" value=""UPDATE""></td>"
		'		oRSNotasCuat.MoveNext()
		'	else
		'	response.Write "<td><input onblur=""this.parentElement.parentElement.cells[0].style.backgroundColor='white';"" onfocus=""this.parentElement.parentElement.cells[0].style.backgroundColor='yellow';"" size=3 id=""nota"" name=""nota"" style=""font-family: Verdana; font-weight: bold; font-size:12px;"" onkeyup=""if (this.value >=6) this.style.color='blue'; if (this.value >= 4 && this.value <6) this.style.color='green'; if (this.value < 4) this.style.color='red';"" onkeypress=""if ((event.keyCode <48 || event.keyCode >=58) && (event.keyCode != 46)) return false;"" maxlength=4 type=""text"" value=""""></td>"
		'	response.Write "<td><input type=""hidden"" id=""alumno"" name=""alumno"" value=""" & oRSAlumnos("IdAlumnoCurso") & """></td>"
		'	response.Write "<td><input type=""hidden"" id=""operacion"" name=""operacion"" value=""INSERT""></td>"
		'	end if
		'else
			response.Write "<td width=""50px""><input type=""text"" onblur=""OnblurNota(this);"" onfocus=""OnfocusNota(this);"" size=3 id=""nota"" name=""nota"" onkeyup=""OnkeyupNota(this);"" onkeypress=""if ((event.keyCode <48 || event.keyCode >=58) && (event.keyCode != 46)) return false;"" maxlength=""4"" value=""" & oRSAlumnos("Nota") & """ " & SetColorNota(oRSAlumnos("Nota")) &  " IdAlumnoCurso=""" & oRSAlumnos("IdAlumnoCurso") & """></td>"
			'response.Write "<td><input type=""hidden"" id=""alumno"" name=""alumno"" value=""" & oRSAlumnos("IdAlumnoCurso") & """></td>"
			'response.Write "<td><input type=""hidden"" id=""operacion"" name=""operacion"" value=""INSERT""></td>"
		'end if
		
		response.Write "</tr>" & vbcrlf
		
		oRSAlumnos.MoveNext
	wend
	response.Write "</table>"
	

	Private function SetColorNota(nota)

		if (nota >=6) then SetColorNota = "style=""color: blue;"""
		
		if (nota >= 4 and nota <6) then SetColorNota = "style=""color: green;"""
		
		if (nota < 4) then SetColorNota = "style=""color: red;"""
	
	End function
	
	Private function GetAlumnosDicMarxMat()
		Dim oConn, sSQL, oRS
	
		Set oConn = OpenConnection
		
		if DicMar = 20 then
		    sSQL =	"select A.IdAlumno, A.Apellido, A.Nombre, C.CursoDescrip, AC.IdAlumnoCurso, N.Nota from Materia M " & _
				    "inner join ProfesorMateria PM on (PM.IdMateria = M.IdMateria) " & _
				    "inner join MateriaCurso MC on (MC.IdProfesorMateria = PM.IdProfesorMateria) " & _
				    "inner join AlumnoCurso AC on (AC.IdMateriaCurso = MC.IdMateriaCurso) " & _
				    "inner join ListadosProcesados LP on (LP.IdAlumnoCurso = AC.IdAlumnoCurso) " & _
				    "inner join Alumno A on (A.IdAlumno = AC.IdAlumno) " & _
				    "inner join Curso C on (C.IdCurso = MC.IdSedeCurso) " & _
				    "left join Nota N on (N.IdAlumnoCurso = LP.IdAlumnoCurso and N.Trimestre = " & DicMar & ") " & _
				    "where M.IdMateria = " & IdMateria
				    if DicMar = 20 then
					    sSQL = sSQL & " and LP.Nota is null and LP.Marzo is null "
				    else
					    sSQL = sSQL & " and LP.Nota is null and LP.Marzo is not null "
				    end if
				    sSQL = sSQL & "order by C.CursoDescrip, A.Apellido, A.Nombre"
          else
            sSQL =  "select A.IdAlumno, A.Apellido, A.Nombre, C.CursoDescrip, AC.IdAlumnoCurso, N.Nota from Materia M " & _
                    "inner join ProfesorMateria PM on (PM.IdMateria = M.IdMateria) " & _
                    "inner join MateriaCurso MC on (MC.IdProfesorMateria = PM.IdProfesorMateria) " & _
                    "inner join AlumnoCurso AC on (AC.IdMateriaCurso = MC.IdMateriaCurso) " & _
                    "inner join ListadosProcesados LP on (LP.IdAlumnoCurso = AC.IdAlumnoCurso) " & _
                    "inner join Alumno A on (A.IdAlumno = AC.IdAlumno) " & _
                    "inner join Curso C on (C.IdCurso = MC.IdSedeCurso) " & _
                    "left join Nota N on (N.IdAlumnoCurso = LP.IdAlumnoCurso and N.Trimestre = 30) " & _
                    "where " & _
                    "M.IdMateria = " & IdMateria & " " & _
                    "and LP.Nota is null " & _
                    "and LP.Marzo is not null " & _
                    "union " & _
                    "select A1.IdAlumno, A1.Apellido, A1.Nombre, C1.CursoDescrip, AC1.IdAlumnoCurso, N2.Nota " & _
                    "from Materia M1 " & _
                    "inner join ProfesorMateria PM1 on (PM1.IdMateria = M1.IdMateria) " & _
                    "inner join MateriaCurso MC1 on (MC1.IdProfesorMateria = PM1.IdProfesorMateria) " & _
                    "inner join AlumnoCurso AC1 on (AC1.IdMateriaCurso = MC1.IdMateriaCurso) " & _
                    "inner join ListadosProcesados LP1 on (LP1.IdAlumnoCurso = AC1.IdAlumnoCurso) " & _
                    "inner join Alumno A1 on (A1.IdAlumno = AC1.IdAlumno) " & _
                    "inner join Curso C1 on (C1.IdCurso = MC1.IdSedeCurso) " & _
                    "inner join Nota N1 on (N1.IdAlumnoCurso = LP1.IdAlumnoCurso and N1.Trimestre = 20 and N1.nota <6) " & _
                    "left join Nota N2 on (N2.IdAlumnoCurso = LP1.IdAlumnoCurso and N2.Trimestre = 30) " & _
                    "where " & _
                    "M1.IdMateria = " & IdMAteria
          end if	
		'response.Write sSQL
		'response.Write " - " & DicMar
		'response.End
		Set oRS = oConn.Execute(sSQL)
		Set GetAlumnosDicMarxMat = oRS
	
	End function
%>